package com.shkco.xbjcc.web.controller;

import com.shkco.exception.GlobalCustomException;
import com.shkco.result.JSONResult;
import com.shkco.xbjcc.dto.SmsCodeDto;
import com.shkco.xbjcc.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifycode")
public class ImageVerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;
    @GetMapping("/imageCode/{key}")
    public JSONResult image(@PathVariable("key")String key){
        try {
            String base64Str = verifyCodeService.getImgCode(key);
            return JSONResult.success(base64Str);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false,"获取图形验证码失败");
        }
    }


    @PostMapping("/sendSmsCode")
    public JSONResult sendSmsCode(@RequestBody SmsCodeDto smsCodeDto){
        verifyCodeService.sendSmsCode(smsCodeDto);
        return JSONResult.success();
    }



}